<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['basic']=$this->plugin_setting('setting');
if($_RQ['op']=='list'){
	//状态为显示的所有视频，排序
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>'1');
	if($_RQ['keyword']){
		$params['title like']='%'.trim($_RQ['keyword']).'%';
	}
	if($_RQ['groupid']){
		$params['groupid']=$_RQ['groupid'];
	}
	//首页展示
	$home_list=pdo_getall('jy_cmsarticle_video',$params,'','','paixu asc');
	//热门
	if($home_list){
		foreach($home_list as &$item){
			if($item['isnet']){
				$item['video'] = $item['videourl'];
			}
		}
	}
	$return['post']=array();
	$return['groups']=pdo_getall('jy_cmsarticle_videogroup',$params);
	$return['list']=$home_list;
	exi($return);
}
if($_RQ['op']=='detail'){
	if(!$_RQ['id']){
		exi('没有找到该视频，请重新选择！','error','jy_cmsarticle/video/list');
	}
	//刷新阅读次数
	pdo_update('jy_cmsarticle_video',array('readnum +='=>1),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
	//查询视频详情
	$item=pdo_get('jy_cmsarticle_video',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$item['msg']=pdo_getall('jy_cmsarticle_comments',array('uniacid'=>$_SESSION['uniacid'],'vid'=>$_RQ['id'],'status'=>1));
	if($item['msg']){
		$item['msgnum']=count($item['msg']);
		foreach($item['msg'] as &$row){
			$row['member']=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$row['uid']));
			$row['createtime']=date('Y-m-d h:i');
		}
	}
	$like=pdo_get('jy_cmsarticle_like',array('uniacid'=>$_SESSION['uniacid'],'user_id'=>$_SESSION['uid'],'vid'=>$_RQ['id']));
	//点赞数量=虚拟点赞数+真实点赞数量
	$vnum=pdo_count('jy_cmsarticle_like',array('uniacid'=>$_SESSION['uniacid'],'vid'=>$_RQ['id'],'vlike'=>1));
	$item['likenum']=$item['likenum']+$vnum;
	$item['createtime']=date('Y-m-d',$item['createtime']);
	$return['account']=$_SESSION['account'];
	$return['like']=$like;
	$return['item']=$item;
	$return['post']=array();
	exi($return);
}
//评论
if($_RQ['op']=='setmsg'){
	$post=get_postdata();
	//print_r($post);exit;
	if(!$post['id']){
		exi('没有找到该视频，请重新选择！','error','jy_cmsarticle/video/list');
	}
	if(empty($post['msg'])){
		exi('请完善评论信息！','error'); 
	}
	$insert=array(
		'uniacid'=>$_SESSION['uniacid'],
		'vid'=>$post['id'],
		'uid'=>$_SESSION['uid'],
		'content'=>$post['msg'],
		'status'=>1,
		'createtime'=>time(),
	
	);
	pdo_insert('jy_cmsarticle_comments',$insert);
	exi('评论成功');
}
if($_RQ['op']=='like'){
	$post=get_postdata();
	if(!$_SESSION['uid']){
		exi('success');
	}
	$id=intval($post['id']);
	$like=intval($post['like']);
	print_r($id.'ff');exit;
	$data=array(
		'vlike'=>$post['like']?1:0,
		'updatetime'=>TIMESTAMP,
	);
	if($id){
		pdo_update('jy_cmsarticle_like',$data,array('id'=>$id,'user_id'=>$_SESSION['uid']));
	/*	if($data['clike']==1){
			pdo_update('jy_cmsarticle_news',array('likenum +='=>1),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		}
		else{
			pdo_update('jy_cmsarticle_news',array('readnum -='=>1),array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		}*/
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['vid']=intval($post['video_id']);
		$data['user_id']=$_SESSION['uid'];
		pdo_insert('jy_cmsarticle_like',$data);
	}
	exi('success');
}